// Learn cc.Class:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
/**
 * 
 * 自己信息
 */
let base = require("panelBase")
let viewConfig = {
    btn_back:{
        node:null,
        name:"top/btn_back",
        eventType:"click",
        cb:"onBtnBackClick"
    },
    head:{
        node:null,
        name:"top/head",
    },
    nickName:{
        node:null,
        name:"top/nickName",

    },
    inviteCode:{
        node:null,
        name:"top/inviteCode",
    },
    btn_copy:{
        node:null,
        name:"top/btn_copy",
        eventType:"click",
        cb:"onBtnCopyClick",
    },
    btn_set:{
        node:null,
        name:"top/btn_set",
        eventType:"click",
        cb:"onBtnSetClick",
    },
    //可开金币
    coin_num:{
        node:null,
        name:"info/info_coin_num",
    },
    // 可提现余额
    yue_num:{
        node:null,
        name:"info/info_yue_num"
    },

    ///广告相关
    banner_icon:{
        node:null,
        name:"banner/icon",
    },
    banner_name:{
        node:null,
        name:"banner/gameName",

    },
    //联系客服按钮
    banner_con_kf:{
        node:null,
        name:"banner/btn_con_kf",
        eventType:"click",
        cb:"onBannerConKfClick"
    },
    //微信群相关

    wc_group_icon:{
        node:null,
        name:"group_des/group_icon",
    },
    wc_group_name:{
        node:null,
        name:"group_des/group_Name",
    },
    wc_group_des:{
        node:null,
        name:"group_des/group_des",
    },
    wc_con_kf:{
        node:null,
        name:"group_des/btn_wc_con_kf",
        eventType:"click",
        cb:"onWcConKfClick",
    },
    banner:{
        node:null,
        name:"banner",
        active:false,
    }

};      
cc.Class({
    extends: base,

    properties: {
        
    },

    init(){
        this._super(viewConfig);
        this.isInited = true;

        cc.tg.eventCenter.addEvent("onGetInviteCode",()=>{
            this.updateInfo(viewConfig["inviteCode"].node,cc.tg.cakeRoom.invicationCode,cc.Label);
        })
        this.onHide();


    },


    onShow(){
        this._super();
        //本地测试数据
        // let testData = {
        //     nickName:"fans",
        //     inviteCode:"qwerdf",
        //     headUrl:"",
        //     coin_num:1000,
        //     yue_num:3.00,
        // }

        // setTimeout(() => {
        //     this.initByData(testData);
        // }, 1000);
        let data = {
            nickName:cc.tg.cakeRoom.accName,
            inviteCode:cc.tg.cakeRoom.invicationCode,
            coin_num:cc.tg.cakeRoom.accGold,
            yue_num:cc.tg.cakeRoom.accMoney
        }   
        if(cc.tg.cakeRoom.invicationCode == null)
        {
            cc.tg.gameLogic.toGetInviteCode();
        }
        else
        {
          
        }
       
        this.initByData(data);
        cc.tg.adDataCenter.toShowAd("my_info");
    },

    initByData(data){
       // this._super(data);
        if(!data)
            return ;
        this.updateInfo(viewConfig["nickName"].node,data.nickName,cc.Label);
        this.updateInfo(viewConfig["inviteCode"].node,data.inviteCode,cc.Label);
        this.updateInfo(viewConfig["coin_num"].node,data.coin_num,cc.Label);
        this.updateInfo(viewConfig["yue_num"].node,data.yue_num,cc.Label);
    },

    onBtnBackClick(){
        this.onHide();
    },
    onHide(){
        this._super();
        cc.tg.adDataCenter.toShowAd("my_info",true);
    },

    onBtnCopyClick(){
        cc.log("on click copy ");
        if(cc.tg.cakeRoom.invicationCode == null)
            return ;
        cc.tg.adDataCenter.copy(cc.tg.cakeRoom.invicationCode);
    },
    onBtnSetClick(){
        cc.log("on click set ");
    },
    //广告里面联系客服
    onBannerConKfClick(){
        cc.log("on click banner kf");
    },
    //微信群联系客服
    onWcConKfClick(){
        cc.log("on click wc kf");
    },

    onDestroy(){
        for(let key in viewConfig)
        {
            viewConfig[key].node = null;
        }
    },
});
